package gof23.structure.bridge;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;

import com.mysql.jdbc.Driver;
import com.mysql.jdbc.NonRegisteringDriver;

public class JDKBridgeDemo {

	public static void main(String[] args) throws Exception {
		//JDBC
		Class.forName("com.mysql.jdbc.Driver");
		//DriverManager.registerDriver(new NonRegisteringDriver());
		//通过DriverInfo引用Driver
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "123");
		
		
		Statement statement = conn.createStatement();
		statement.execute("show databases");		
		ResultSet resultSet =  statement.getResultSet();
		resultSet.next();
		System.out.println(resultSet.getString(1));
		
		//Loging
		Logger logger = Logger.getLogger(JDKBridgeDemo.class.getName());
		logger.setLevel(Level.FINEST);
		
		/**
		 * Handler与Formatter为桥接
		 */
		ConsoleHandler consoleHandler = new ConsoleHandler();
		consoleHandler.setFormatter(new XMLFormatter());
		consoleHandler.setLevel(Level.INFO);
		logger.addHandler(consoleHandler);
		
		logger.info("日志信息");
		
		
		
		System.out.println();
	}
}
